package jdbc;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.PreparedStatement;

@Slf4j
public class RepresentativeHandler implements InvocationHandler {

    // 需要代理的实际对象
    private PreparedStatement person;

    public RepresentativeHandler(PreparedStatement person) {
        this.person = person;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        log.debug("方法{} 被调用，参数为{}", method.getName(), StrUtil.join(",", args));
        Object result = method.invoke(person, args);
        log.debug("方法{}完成调用", method.getName());
        return result;
    }
}